<script>
$("#dialog").dialog( "option", "width", $(window).width()*0.85 ).dialog( "option", "height", $(window).height()*0.7).dialog( "option", "position", [10,0]);
$(window).resize(function() {
    $("#dialog").dialog( "option", "width", $(window).width()*0.85 ).dialog( "option", "height", $(window).height()*0.7).dialog( "option", "position", [10,0]);
});



$(function() {
    $("#dialog").dialog("option", "title", "<?echo $this->controllerName.':'.$this->actionName?>");
    $(".fecha").datepicker();   

    font_size= $.cookie("sgit_font_size") || 1;      
    $("#dialog").css("font-size",font_size+"em");     
});    




$('#ajax_form input[name=internet]').css('width',60);
$('#ajax_form input[name=backup]').css('width',60);
$('#ajax_form input[name=firewall]').css('width',60);




$("#ajax_form select[name=id_proyecto]").change(function () {
    var id_proyecto=$(this).val();
    if(id_proyecto)
    {
       
        
    }else{
        $("#ajax_form input[name=pep]").val('');
    }
                
})



function Isx50(objeto){
	var value=$(objeto).val();
    
    if (value%50!=0) {
		$(objeto).css('border','2px solid #FF2A2A')
		$(objeto).focus()
		alert('El campo storage solo puede ser multiplo de 50.')
		return false;
	}
    
	$(objeto).css('border','1px solid #C0C0C0')
	return true;
}


function Is124(objeto){
	var value=$(objeto).val();

    if(value=='')return true;
    if (Math.abs(value)!=1 && Math.abs(value)!=2 && Math.abs(value)!=4 && Math.abs(value)!=8) {
		$(objeto).css('border','2px solid #FF2A2A')
		$(objeto).focus()
		alert('El campo RAM solo puede ser 1, 2 , 4 o 8.')
		return false;
	}
    
	$(objeto).css('border','1px solid #C0C0C0')
	return true;
}

function validate(formData, jqForm, options) { 
    
    if(!$("#ajax_form input[name=pep]").val() && !$("#ajax_form select[name=id_proyecto]").val()){
        alert('Se necesita Cliente o PEP');
        return false; 
    }
    
    if(!IsRequired('#ajax_form select[name=id_proyecto]','Proyecto'))return false; 
    if(!IsRequired('#ajax_form input[name=fecha_alta]','Fecha Alta'))return false; 

    var error = false;
    $('#ajax_form .storage').map(function() {
         if(!Isx50(this)) error=true; 
    })
    $('#ajax_form .ram').map(function() {
         if(!Is124(this)) error=true; 
    })
    
    $('#ajax_form select[name*="id_tipo_servidor"]').map(function() {
        if(!IsRequired(this,'Tipo Servidor')) error=true; 
    })
    $('#ajax_form input[name*="internet"]').map(function() {
        if(!IsInteger(this,'internet')) error=true; 
    })
        
    if(error)    return false; 
    else  return true; 


    return true; 
}


</script>	



<?=$this->form('ajax_form', array('method'=>'POST','id'=>'ajax_form','action'=>$this->baseUrl('utility-computing-servidores/editar/id/'.$this->id.'/idZona/'.$this->idZona))); ?>
    <table class="tableform">
    <tr>
        <td class="ui-widget-header"><span class="ui-icon ui-icon-star myicon"></span>Cliente</td><td><?=$this->formSelect('id_proyecto',$this->row['id_proyecto'] , 'null', $this->proyectos)?> </td>
        <td class="ui-widget-header"><span class="ui-icon ui-icon-star myicon"></span>PEP</td><td> <?=$this->formText('pep', $this->row['pep'])?></td>
    </tr>
    <tr>
        <td class="ui-widget-header">Ticket NEC</td><td> <?=$this->formText('ticket_nec', $this->row['ticket_nec'])?></td>
        <td class="ui-widget-header">Ticket Cliente</td><td> <?=$this->formText('ticket_cliente', $this->row['ticket_cliente'])?></td>
    </tr>
    <tr>
        <td class="ui-widget-header"><span class="ui-icon ui-icon-star myicon"></span>Fecha Alta</td><td> <?=$this->formText('fecha_alta', $this->row['fecha_alta'],array('class'=>'fecha'))?></td>
        <td class="ui-widget-header">Fecha Baja</td><td> <?=$this->formText('fecha_baja', $this->row['fecha_baja'],array('class'=>'fecha'))?></td>
    </tr>
</table>
        
 <div id="server" class="server">
    <table class="tableform" id="fila_servidor" width="80%">
        <tr class="ui-widget-header">
            <th><span class="ui-icon ui-icon-star myicon"></span>Tipo Servidor</th>
            <th>Nombre Servidor</th>
            <th>Internet (Mbps)</th>
            <th>Monitorización</th>
            <th>Backup (GB)</th>
            <th>Firewall (Reglas)</th>
        </tr>
        <tr>
            <td><?=$this->formSelect('id_tipo_servidor', $this->row['id_tipo_servidor'],'',$this->tipo_servidor)?></td>
            <td><?=$this->formText('nombre_servidor', $this->row['nombre_servidor'])?></td>
            <td><?=$this->formText('internet', $this->row['internet'])?></td>
            <td><?=$this->formCheckbox('monitor', null,array('checked' => $this->row['monitor']))?></td>
            <td><?=$this->formText('backup', $this->row['backup'])?></td>
            <td><?=$this->formText('firewall', $this->row['firewall'])?></td>
            

        </tr>
    </table>
 </div>
 <br />
        
 <table >
 <caption class="ui-widget-header">Extra</caption>
     <tr>
         <th class="ui-widget-header"></th>
         <td class="ui-widget-header">Fecha Ampliación</td>
         <td class="ui-widget-header">Cantidad Ampliada</td>
         <td class="ui-widget-header">LUN</td>
     </tr>
    
    <?foreach((array)$this->extra as $v):?>
    <tr>
        <th class="ui-widget-header"><?=$v['tipo']?></th>
        <td><?=$this->formText('fecha['.$v['id'].']',Sgit_Filter_DateTo::filter($v['fecha']),array('class'=>'fecha'))?></td>
        <td><?=$this->formText('cantidad['.$v['id'].']',$v['cantidad'],array('class'=>$v['tipo']))?>
        <td><?if($v['tipo']=='storage') print $this->formText('lun['.$v['id'].']',$v['lun'],array('class'=>'lun'))?></td>
    </tr>
    <?endforeach?>
    <tr>
        <th class="ui-widget-header">Storage</th>
        <td><?=$this->formText('fecha_storage','',array('class'=>'fecha'))?></td>
        <td><?=$this->formText('cantidad_storage', '',array('class'=>'storage'))?></td>
        <td><?=$this->formText('cantidad_lun', '',array('class'=>'lun'))?></td>
    </tr>
    <tr>
        <th class="ui-widget-header">RAM</th>
        <td><?=$this->formText('fecha_ram', '',array('class'=>'fecha'))?></td>
        <td><?=$this->formText('cantidad_ram', '',array('class'=>'ram'))?></td>
        <td></td>
    </tr>
</table>
</form>


<?php

echo $this->partial('form_js.phtml', 
    array(	
        'actionName'=>$this->actionName,
        'id'=>$this->id,
        'id_tablesorter'=>$this->id_tablesorter,
        )
);
